package com.yuneec.droneservice.command;

import com.yuneec.droneservice.model.GPSTime;
import com.yuneec.droneservice.request.IResponse;
import com.yuneec.droneservice.utils.ByteUtils;

import java.util.Arrays;

/**
 * Created by gjw on 2017/3/27.
 */

public class GetGpsTime extends BaseCommand {

    public GetGpsTime() {
        super(MAV_RC_COMMAND.MAV_RC_CMD_GET_GPS_TIME);
    }

    @Override
    public IResponse<GPSTime> toResponse(byte[] data, int off, int len) {
        int code = data[off + 1] & 0xff;
        IResponse<GPSTime> response = new IResponse(ids(), code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            GPSTime gpsTime = new GPSTime();
            gpsTime.setYear(ByteUtils.byteArrayToShort(Arrays.copyOfRange(data, off + 2, off + 4), IS_BIGENDIAN));
            gpsTime.setMonth(data[off + 4]);
            gpsTime.setDay(data[off + 5]);
            gpsTime.setHour(data[off + 6]);
            gpsTime.setMinute(data[off + 7]);
            gpsTime.setSenond(data[off + 8]);
            response.setParam(gpsTime);
        }
        return response;
    }

}
